(function () {
    /**
     * 收获弹窗
     * @class AlertCashoutUI
     * @constructor
     */
    function AlertCashoutUI() {
        AlertCashoutUI.super(this);
        this.isPopup = false;
        this.custom = true;

        this.bindEvent();
    }
    Laya.class(AlertCashoutUI, "ui.Alert.Cashout", ui.Alert.CashoutUI);

    var _proto = AlertCashoutUI.prototype;
    /**
     * @privite
     * 绑定相关事件
     */
    _proto.bindEvent = function () {
        this.btnClose.on(Laya.Event.CLICK, this, function () {
            this.close();
        })
        //兑出
        this.btnCashout.on(Laya.Event.CLICK, this, function () {
            viewer.publish("io.emit", {
                cmd : "user::exchangeAfter",
                params : {
                    token : token
                }
            });
            viewer.publish("alert.tip", "您已成功收获！", 3000, 0.7);
            this.close();
        });

        //显示别处游戏币
        this.btnShowAnother.on(Laya.Event.CLICK, this, function () {
            this.close();
            if(window.GM && GM.whereYxb){
                GM.whereYxb();
            };
        });

        this.detailsList.renderHandler = new Laya.Handler(this, function (item, index) {
            var type = item.getChildByName("type");
            var text = item.getChildByName("text");

            var xOffset = type.text.length * 26;

            text.x = xOffset;
            // text.width = 135 - xOffset;
        });

        //注册收获相关事件
        viewer.register("user::exchangeBefore", this.update.bind(this));
        viewer.register("user::exchangeAfter", this.exchange.bind(this));
    }
    _proto.resize = function (size) {
        this.detailsList.height = size * 60;
        this.alertContent.height = 450 + size * 60;
        this.infoMask.height = 118 + size * 60;
    }
    /**
     * @public
     * 显示收获弹窗
     */
    _proto.display = function () {
        this.isPopup = true;
        this.width = Laya.stage.width;

        this.detailsList.array = [];
        this.resize(0);

        viewer.publish("io.emit", {cmd : "user::exchangeBefore", params : {token : token}});

        Laya.stage.addChild(this);
    }
    /**
     * @public
     * 更新弹窗相关数据
     * 
     * @param {Object} data 兑出相关数据
     */
    _proto.update = function (data) {
        var gameCoin = data.countUp.d.a || 0;
        var _name = {"1" : "欢乐值", "2" : "万里通积分", "3" : "欢乐豆", "4" : "彩金", "5" : "挺豆", "9" : "彩分", "10" : "健康金余额", "11" : "流量余额"};

        var details = data.details;
        var size = details.length;
        var _data = [];

        this.detailsList.array = [];
        this.gameCoin.text = gameCoin;

        for(var i in details){
            var text = details[i].amountAvailable;
            if(details[i].accountType == 10){
                if(GM && GM.is_jiankangjin_user == true){
                    //text = text == 0 ? "0 前往好医生APP获取更多健康金" : text;
                    text = text == 0 ? "0 前往好医生APP获取更..." : text;
                }else{
                    continue;
                }
            }
            _data.push({type : _name[details[i].accountType] + "：", text : text});
        }

        this.detailsList.array = _data;

        this.resize(size)
    }
    /**
     * @public
     * 兑出成功以后更新用户数据
     */
    _proto.exchange = function () {
        viewer.publish("io.emit", {
            cmd: 'user::getUserAmount',
            params : {
                token : token
            }
        });
    }
    /**
     * @public
     * 关闭聊天弹窗，重置相关变量
     */
    _proto.close = function () {
        this.isPopup = false;

        this.removeSelf();
    }
})();